package Demo;

public class Demo12 {
    public static void main(String[] args) {
        Object object = new Object();
        Thread t1 = new Thread(() ->{
            while(true){
                synchronized (object){
                    System.out.println("wait 之前");
                    try {
                        object.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    System.out.println("wait 之后");
                }
            }
        });
        t1.start();
        Thread t2 = new Thread(() ->{
            while(true){
                synchronized (object){
                    System.out.println("notify 之前");
                    object.notify();
                    object.notifyAll();
                    System.out.println("notify 之后");
                }
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        t2.start();
    }
}
